package cn.ac.jaas.isc.vegetable.quartz.config;

import cn.ac.jaas.isc.vegetable.quartz.constants.VegetableQuartzEnum;
import cn.ac.jaas.isc.vegetable.quartz.entity.SysJob;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 张高昌
 * @date 2022/4/30 16:16
 * @description: 动态任务工厂
 */
@Slf4j
@DisallowConcurrentExecution
public class VegetableQuartzFactory implements Job {

    @Autowired
    private VegetableQuartzInvokeFactory vegetableQuartzInvokeFactory;

    @Override
    @SneakyThrows
    public void execute(JobExecutionContext jobExecutionContext) {
        SysJob sysJob = (SysJob) jobExecutionContext.getMergedJobDataMap()
                .get(VegetableQuartzEnum.SCHEDULE_JOB_KEY.getType());
        vegetableQuartzInvokeFactory.init(sysJob, jobExecutionContext.getTrigger());
    }

}
